package com.itheima.thread;

public class Demo02 {

    public static void main(String[] args) throws InterruptedException {
        MyRunnable my = new MyRunnable();
        Thread t1 = new Thread(my,"小蔡");
        t1.start();
        Thread t2 = new Thread(my,"小黄");
        t2.start();
        for (int i = 0; i < 100; i++) {
            Thread.sleep(2000);
            System.out.println("main:"+i);
        }
    }
}
class MyRunnable implements Runnable{

    @Override
    public void run() {
        Thread thread = Thread.currentThread();
        String name = thread.getName();
        for (int i = 0; i < 100; i++) {
            try {
                Thread.sleep(1000);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            System.out.println(name+":"+i);
        }
    }
}